# coding: utf-8

from collections import namedtuple

class BorrowCardApplyStatus(object):
    APPLY_STATUS = namedtuple('APPLY_STATUS', ['name', 'value'])
    FAILED = APPLY_STATUS(name='申请失败', value=-1)
    UNAPPLY = APPLY_STATUS(name='未申请', value=0)
    APPLYING = APPLY_STATUS(name='申请中', value=1)
    APPLIED = APPLY_STATUS(name='已申请', value=2)

class OverdueFee(object):
    OVERDUE_FEE = namedtuple('OVERDUE_FEE', ['name', 'value'])
    FEE_PER_DAY = OVERDUE_FEE(name='每天超期费', value=0.5)


roles_data = [
    {'role_name': '普通用户', 'role_key': 'ROLE_USER'},
    {'role_name': '图书管理员', 'role_key': 'ROLE_BOOK_ADMIN'},
    {'role_name': '系统管理员', 'role_key': 'ROLE_SYS_ADMIN'}
]

# perms_data = [
#     {'perm_name': '借书', 'perm_key': 'PERM_BORROW'},
#     {'perm_name': '还书', 'perm_key': 'PERM_RETURN'},
#     {'perm_name': '申请借阅证', 'perm_key': 'PERM_BORROW_CARD_APPLY'},
#     {'perm_name': '审批借阅证', 'perm_key': 'PERM_BORROW_CARD_APPROVAL'},
#     {'perm_name': '查询书籍', 'perm_key': 'PERM_BOOK_VIEW'},
#     {'perm_name': '添加书籍', 'perm_key': 'PERM_BOOK_ADD'},
#     {'perm_name': '编辑书籍信息', 'perm_key': 'PERM_BOOK_EDIT'},
#     {'perm_name': '处理借书', 'perm_key': 'PERM_BOOK_BORROW'},
#     {'perm_name': '处理还书', 'perm_key': 'PERM_BOOK_RETURN'},
#     {'perm_name': '删除书籍', 'perm_key': 'PERM_BOOK_DELETE'},
#     {'perm_name': '查询用户', 'perm_key': 'PERM_USER_VIEW'},
#     {'perm_name': '添加用户', 'perm_key': 'PERM_USER_ADD'},
#     {'perm_name': '修改用户信息', 'perm_key': 'PERM_USER_EDIT'},
#     {'perm_name': '删除用户', 'perm_key': 'PERM_USER_DELETE'}
# ]


class PERMISSION(object):
    PERM_KEY = namedtuple('PERM_KEY', ['name', 'KEY', 'ROLE_KEYS'])
    # 借书、还书 -- 普通用户权限
    PERM_BORROW = PERM_KEY(name='借书', KEY='PERM_BORROW', ROLE_KEYS=["ROLE_USER"])
    PERM_RETURN = PERM_KEY(name='还书', KEY='PERM_RETURN', ROLE_KEYS=["ROLE_USER"])
    
    # 申请借阅证 -- 普通用户权限
    PERM_BORROW_CARD_APPLY = PERM_KEY(name='申请借阅证', KEY='PERM_BORROW_CARD_APPLY', ROLE_KEYS=["ROLE_USER"])
    # 查询借阅证、审批借阅证 -- 管理员权限
    PERM_BORROW_CARD_APPROVAL = PERM_KEY(name='审批借阅证', KEY='PERM_BORROW_CARD_APPROVAL', ROLE_KEYS=["ROLE_BOOK_ADMIN"])
    
    # 查询书籍 -- 普通用户权限、管理员权限
    PERM_BOOK_VIEW = PERM_KEY(name='查询书籍', KEY='PERM_BOOK_VIEW', ROLE_KEYS=["ROLE_USER","ROLE_BOOK_ADMIN"])
    # 添加书籍、编辑书籍、删除书籍 -- 管理员权限
    PERM_BOOK_ADD = PERM_KEY(name='添加书籍', KEY='PERM_BOOK_ADD', ROLE_KEYS=["ROLE_BOOK_ADMIN"])
    PERM_BOOK_EDIT = PERM_KEY(name='编辑书籍', KEY='PERM_BOOK_EDIT', ROLE_KEYS=["ROLE_BOOK_ADMIN"])
    PERM_BOOK_DELETE = PERM_KEY(name='删除书籍', KEY='PERM_BOOK_DELETE', ROLE_KEYS=["ROLE_BOOK_ADMIN"])

    # 处理借书、处理还书 -- 管理员权限
    PERM_BOOK_HANDLE_BORROW = PERM_KEY(name='处理借书', KEY='PERM_BOOK_HANDLE_BORROW', ROLE_KEYS=["ROLE_BOOK_ADMIN"])
    PERM_BOOK_HANDLE_RETURN = PERM_KEY(name='处理还书', KEY='PERM_BOOK_HANDLE_RETURN', ROLE_KEYS=["ROLE_BOOK_ADMIN"])

    # 查询用户、添加用户、编辑用户、删除用户 -- 管理员权限
    PERM_USER_VIEW = PERM_KEY(name='查询用户', KEY='PERM_USER_VIEW', ROLE_KEYS=["ROLE_SYS_ADMIN"])
    PERM_USER_ADD = PERM_KEY(name='添加用户', KEY='PERM_USER_ADD', ROLE_KEYS=["ROLE_SYS_ADMIN"])
    PERM_USER_EDIT = PERM_KEY(name='编辑用户', KEY='PERM_USER_EDIT', ROLE_KEYS=["ROLE_SYS_ADMIN"])
    PERM_USER_DELETE = PERM_KEY(name='删除用户', KEY='PERM_USER_DELETE', ROLE_KEYS=["ROLE_SYS_ADMIN"])

perms_data = [getattr(PERMISSION,x) for x in dir(PERMISSION) if x.startswith("PERM_") and x != "PERM_KEY"]